package com.bacon.gmall.mq.controller;

import com.bacon.gmall.common.result.Result;
import com.bacon.gmall.common.utils.RabbitUtil;
import com.bacon.gmall.mq.config.DeadLetterMqConfig;
import com.bacon.gmall.mq.config.DelayMQConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author： bacon、
 * @version： 1.0
 * @create： 2021-01-08 16:57
 * @description:
 */
@RestController
@RequestMapping("/api/mq")
public class RabbitService {

    @Autowired
    private RabbitUtil rabbitUtil;

    @GetMapping("/sendMessage")
    public Result sendMessage(String message) {
        rabbitUtil.sendMessage(
                "exchageBacon",
                "routingKeyBacon",
                message);
        return Result.ok();
    }

    //发送延迟消息队列
    @GetMapping("/sendDeadLetterMessage")
    public Result sendDeadLetterMessage(String message, int delay) {
        rabbitUtil.sendDeadLetterMessage(
                DeadLetterMqConfig.exchange_dead,
                DeadLetterMqConfig.routing_dead_1,
                message,
                delay);
        return Result.ok();
    }

    //发送消息 延迟插件的延迟消息
    @GetMapping("/sendDelayMessage")
    public Result sendDelayMessage(String message, int delay) {
        rabbitUtil.sendDelayMessage(
                DelayMQConfig.exchange_delay,
                DelayMQConfig.routing_delay,
                message,
                delay);
        return Result.ok();
    }
}
